﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DGSFramework;
using System.Web.Security;
using CodeCarvings.Piczard.Web;
using CodeCarvings.Piczard;
using System.IO;

namespace Framework.WebmasterTool.Advertisings
{
    public partial class AdvertisingAdd : System.Web.UI.Page
    {
        DGSFrameworkEntities entity = new DGSFrameworkEntities();

        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Form.Attributes.Add("enctype", "multipart/form-data");
            //txtRealeaseDate.Attributes.Add("readonly", "readonly");
            //txtExpireDate.Attributes.Add("readonly", "readonly");
            if (!IsPostBack)
            {
                CheckPermission();
                //CleanImageUploadTemp();
                CallImageUploads();
                LoadAdvertisingDetails();
            }
        }

        public void CheckPermission()
        {
            MembershipUser someUser = Membership.GetUser();
            if (someUser == null)
            {
                Response.Redirect(Globals.ApplicationPath + "LoginAdmin/Default.aspx");
            }
            bool flag = false;
            var user = entity.aspnet_Users.Where(us => us.UserName == someUser.UserName).FirstOrDefault();
            user.aspnet_Roles.Load();
            var rolesForUser = user.aspnet_Roles.ToList();
            foreach (var item in rolesForUser)
            {
                var permission = entity.udv_Permissions.Where(ps => ps.RoleId == item.RoleId).FirstOrDefault();
                if (permission.Advertising.Value == true)
                {
                    flag = true;
                }
            }
            if (flag == false)
            {
                lblPermissionMessage.Visible = true;
                Panel1.Visible = false;
            }
        }

        public void LoadAdvertisingDetails()
        {
            if (Request.QueryString["AdvID"] != null)
            {
                int advertisingID = 0;
                int.TryParse(Request.QueryString["AdvID"].ToString(), out advertisingID);
                udv_Advertise advertising = entity.udv_Advertise.Where(ad => ad.AdvID == advertisingID).FirstOrDefault();
                if (advertising != null)
                {
                    txtCustomerName.Text = advertising.CustomerName.Trim();
                    txtAddress.Text = advertising.Address.Trim();
                    txtPhone.Text = advertising.Phone.Trim();
                    txtFax.Text = advertising.Fax.Trim();
                    txtEmail.Text = advertising.Email.Trim();
                    txtAdvTitle.Text = advertising.AdvName.Trim();
                    txtAdvTitle_en.Text = advertising.AdvName_en.Trim();
                    ddlPosition.SelectedValue = advertising.Position.ToLower().Trim();
                    if (advertising.IsFlash.Value == true)
                    {
                        rdbIsFlash.Checked = true;
                        rdbIsImage.Checked = false;
                        rdbIsMedia.Checked = false;
                        rdbIsGif.Checked = false;

                        FileUpload1.Visible = true;
                        FileUpload2.Visible = false;
                        siuUploadAdvertising.Visible = false;
                        txtMedia.Visible = false;
                        imgGif.Visible = false;

                        divFlash.Visible = true;
                        divFlash.InnerHtml = "<embed src='" + ConfigPaths.Path_Advertisings_Folder.Substring(1) + advertising.AdvURL + "' quality='high' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + advertising.AdvWidth.ToString() + "' height='" + advertising.AdvHeight.ToString() + "'></embed>";
                    }
                    else if (advertising.IsCode.Value == true)
                    {
                        rdbIsFlash.Checked = false;
                        rdbIsImage.Checked = false;
                        rdbIsMedia.Checked = true;
                        rdbIsGif.Checked = false;

                        FileUpload1.Visible = false;
                        FileUpload2.Visible = false;
                        siuUploadAdvertising.Visible = false;
                        txtMedia.Visible = true;
                        imgGif.Visible = false;

                        txtMedia.Text = HttpUtility.HtmlDecode(advertising.AdvCode.Trim());
                        ltrMedia.Text = HttpUtility.HtmlDecode(advertising.AdvCode.Trim());
                    }
                    else
                    {
                        rdbIsFlash.Checked = false;
                        rdbIsMedia.Checked = false;

                        FileUpload1.Visible = false;
                        siuUploadAdvertising.Visible = true;
                        txtMedia.Visible = false;
                        imgGif.Visible = false;

                        if (advertising.AdvURL.ToLower().Contains(".gif"))
                        {
                            rdbIsGif.Checked = true;
                            rdbIsImage.Checked = false;
                            FileUpload2.Visible = true;
                            siuUploadAdvertising.Visible = false;
                            imgGif.Visible = true;
                            imgGif.Src = ConfigPaths.Path_Advertisings_Folder.Substring(1) + advertising.AdvURL;
                        }
                        else
                        {
                            rdbIsGif.Checked = false;
                            rdbIsImage.Checked = true;
                            FileUpload2.Visible = false;
                            string sourceImageFilePath = ConfigPaths.Path_Advertisings_Folder_MapPath + advertising.AdvURL;
                            siuUploadAdvertising.LoadImageFromFileSystem(Server.MapPath(sourceImageFilePath));
                        }
                    }
                    txtWidth.Text = advertising.AdvWidth.ToString();
                    txtHeight.Text = advertising.AdvHeight.ToString();
                    txtLink.Text = advertising.AdvLink.Trim();
                    txtRealeaseDate.Text = String.Format("{0:dd/MM/yyyy hh:mm:ss tt}", advertising.ReleaseDate);
                    txtExpireDate.Text = String.Format("{0:dd/MM/yyyy hh:mm:ss tt}", advertising.ExpireDate);
                    txtDisplayOrder.Text = advertising.DisplayOrder.ToString();
                    chkIsActive.Checked = advertising.IsActive.Value;
                    lblAddedBy.Text = advertising.AddedBy;
                    lblAddedDate.Text = String.Format("{0:dd/MM/yyyy HH:mm:ss tt}", advertising.AddedDate);
                    lblUpdatedBy.Text = advertising.UpdatedBy;
                    lblUpdatedDate.Text = String.Format("{0:dd/MM/yyyy HH:mm:ss tt}", advertising.UpdatedDate);
                    advertising.udv_ReportAdvertise.Load();
                    lblClickCount.Text = advertising.udv_ReportAdvertise.Count.ToString();
                }
                else
                {
                    Response.Redirect("Default.aspx");
                }
            }
        }

        protected void rdbIsImage_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbIsImage.Checked == true)
            {
                siuUploadAdvertising.Visible = true;
                FileUpload1.Visible = false;
                FileUpload2.Visible = false;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else if (rdbIsFlash.Checked == true)
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = true;
                FileUpload2.Visible = false;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else if (rdbIsGif.Checked == true)
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = false;
                FileUpload2.Visible = true;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = false;
                FileUpload2.Visible = false;
                txtMedia.Visible = true;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
        }

        protected void rdbIsFlash_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbIsImage.Checked == true)
            {
                siuUploadAdvertising.Visible = true;
                FileUpload1.Visible = false;
                FileUpload2.Visible = false;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else if (rdbIsFlash.Checked == true)
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = true;
                FileUpload2.Visible = false;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else if (rdbIsGif.Checked == true)
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = false;
                FileUpload2.Visible = true;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = false;
                FileUpload2.Visible = false;
                txtMedia.Visible = true;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
        }

        protected void rdbIsMedia_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbIsImage.Checked == true)
            {
                siuUploadAdvertising.Visible = true;
                FileUpload1.Visible = false;
                FileUpload2.Visible = false;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else if (rdbIsFlash.Checked == true)
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = true;
                FileUpload2.Visible = false;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else if (rdbIsGif.Checked == true)
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = false;
                FileUpload2.Visible = true;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = false;
                FileUpload2.Visible = false;
                txtMedia.Visible = true;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
        }

        protected void rdbIsGif_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbIsImage.Checked == true)
            {
                siuUploadAdvertising.Visible = true;
                FileUpload1.Visible = false;
                FileUpload2.Visible = false;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else if (rdbIsFlash.Checked == true)
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = true;
                FileUpload2.Visible = false;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else if (rdbIsGif.Checked == true)
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = false;
                FileUpload2.Visible = true;
                txtMedia.Visible = false;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
            else
            {
                siuUploadAdvertising.Visible = false;
                FileUpload1.Visible = false;
                FileUpload2.Visible = false;
                txtMedia.Visible = true;
                ScriptManager.RegisterStartupScript(this.UpdatePanel2, typeof(string), "Script", "$(document).ready(function () {$('.ImageUpload > div > div:last-child').css('display', 'none');});", true);
            }
        }

        public void ImageUpload(SimpleImageUpload ctrImageUpload)
        {
            ctrImageUpload.ImageBackColorApplyMode = PictureTrimmerImageBackColorApplyMode.DoNotApply;
            ctrImageUpload.CropConstraint = new FreeCropConstraint();
            ctrImageUpload.PreviewFilter = new FixedResizeConstraint(200, 200, System.Drawing.Color.Black);
            ctrImageUpload.Text_BrowseButton = "Upload ảnh";
            ctrImageUpload.Text_CancelUploadButton = "Huỷ";
            ctrImageUpload.Text_EditButton = "Sửa ảnh";
            ctrImageUpload.Text_RemoveButton = "Xoá ảnh";
        }

        public void CallImageUploads()
        {
            ImageUpload(siuUploadAdvertising);
        }

        public void CleanImageUploadTemp()
        {
            foreach (var file in Directory.GetFiles(Server.MapPath(ConfigPaths.Path_ImageUploadTemp_Folder_MapPath)))
            {
                File.Delete(file);
            }
        }

        public bool CheckExtensionFlash(string ImageName)
        {
            string strExtension = System.IO.Path.GetExtension(ImageName).ToUpper();
            if (strExtension == ".SWF" || strExtension == ".FLV")
                return true;
            else
                return false;
        }

        public bool CheckExtensionGif(string imageName)
        {
            string strExtension = System.IO.Path.GetExtension(imageName).ToUpper();
            if (strExtension == ".GIF")
                return true;
            else
                return false;
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (rdbIsImage.Checked)
            {
                if (!siuUploadAdvertising.HasImage)
                {
                    lblMessage.Text = "Chưa upload ảnh";
                    return;
                }
            }
            else if (rdbIsGif.Checked)
            {
                if (imgGif.Visible == false && !FileUpload2.HasFile)
                {
                    lblMessage.Text = "Chưa upload ảnh động";
                    return;
                }
                if (FileUpload2.HasFile && !CheckExtensionGif(FileUpload2.FileName))
                {
                    lblMessage.Text = "Ảnh động không đúng định dạng";
                    return;
                }
            }
            else if (rdbIsFlash.Checked)
            {
                if (divFlash.Visible == false && !FileUpload1.HasFile)
                {
                    lblMessage.Text = "Chưa upload flash";
                    return;
                }
                if (FileUpload1.HasFile && !CheckExtensionFlash(FileUpload1.FileName))
                {
                    lblMessage.Text = "Flash không đúng định dạng";
                    return;
                }
            }
            else
            {
                if (txtMedia.Text.Trim() == "")
                {
                    lblMessage.Text = "Chưa chèn code media";
                    return;
                }
            }
            if (Request.QueryString["AdvID"] == null)
            {
                udv_Advertise advertising = new udv_Advertise();
                advertising.AdvName = txtAdvTitle.Text.Trim();
                advertising.AdvName_en = txtAdvTitle_en.Text.Trim();
                advertising.AdvWidth = int.Parse(txtWidth.Text);
                advertising.AdvHeight = int.Parse(txtHeight.Text);
                advertising.Position = ddlPosition.SelectedValue.ToLower().Trim();
                if (rdbIsImage.Checked)
                {
                    string fileNameImage = Globals.GetFileName(siuUploadAdvertising.SourceImageClientFileName);
                    siuUploadAdvertising.SaveProcessedImageToFileSystem(ConfigPaths.Path_Advertisings_Folder + fileNameImage);

                    advertising.IsFlash = false;
                    advertising.IsCode = false;

                    advertising.AdvURL = fileNameImage;
                    advertising.AdvCode = "";
                }
                else if (rdbIsGif.Checked)
                {
                    string fileNameImage = Globals.GetFileName(FileUpload2.FileName);
                    FileUpload2.SaveAs(Server.MapPath(ConfigPaths.Path_Advertisings_Folder_MapPath + fileNameImage));

                    advertising.IsFlash = false;
                    advertising.IsCode = false;

                    advertising.AdvURL = fileNameImage;
                    advertising.AdvCode = "";
                }
                else if (rdbIsFlash.Checked)
                {
                    string fileNameImage = Globals.GetFileName(FileUpload1.FileName);
                    FileUpload1.SaveAs(Server.MapPath(ConfigPaths.Path_Advertisings_Folder_MapPath + fileNameImage));

                    advertising.IsFlash = true;
                    advertising.IsCode = false;

                    advertising.AdvURL = fileNameImage;
                    advertising.AdvCode = "";
                }
                else
                {

                    advertising.IsFlash = false;
                    advertising.IsCode = true;

                    advertising.AdvURL = "";
                    advertising.AdvCode = HttpUtility.HtmlEncode(txtMedia.Text.Trim());
                }
                advertising.AdvLink = txtLink.Text.Trim();
                advertising.AddedBy = Membership.GetUser().UserName;
                advertising.AddedDate = DateTime.Now;
                advertising.UpdatedBy = Membership.GetUser().UserName;
                advertising.UpdatedDate = DateTime.Now;
                if (txtRealeaseDate.Text.Trim() != "")
                {
                    advertising.ReleaseDate = DateTime.ParseExact(txtRealeaseDate.Text.Trim(), "dd/MM/yyyy hh:mm:ss tt", null);
                }
                if (txtExpireDate.Text.Trim() != "")
                {
                    advertising.ExpireDate = DateTime.ParseExact(txtExpireDate.Text.Trim(), "dd/MM/yyyy hh:mm:ss tt", null);
                }
                advertising.DisplayOrder = int.Parse(txtDisplayOrder.Text);
                advertising.IsActive = chkIsActive.Checked;
                advertising.ClickCount = 0;
                advertising.CustomerName = txtCustomerName.Text.Trim();
                advertising.Address = txtAddress.Text.Trim();
                advertising.Phone = txtPhone.Text.Trim();
                advertising.Fax = txtFax.Text.Trim();
                advertising.Email = txtEmail.Text.Trim();
                entity.AddToudv_Advertise(advertising);
                entity.SaveChanges();
                //create db log
                CreateDBLog(null, null, TypeAction.Insert, "Tạo quảng cáo: " + advertising.AdvName + " - " + advertising.CustomerName, "", 
                    "", advertising.ReleaseDate != null ? string.Format("{0:dd/MM/yyyy HH:mm:ss}", advertising.ReleaseDate) : "", 
                    advertising.ExpireDate != null ? string.Format("{0:dd/MM/yyyy HH:mm:ss}", advertising.ExpireDate) : "", "", "", "", "");
                //redirect page
                Response.Redirect("Default.aspx");
            }
            else
            {
                int advertisingID = 0;
                int.TryParse(Request.QueryString["AdvID"].ToString(), out advertisingID);
                udv_Advertise advertising = entity.udv_Advertise.Where(ad => ad.AdvID == advertisingID).FirstOrDefault();
                if (advertising != null)
                {
                    string oldTitle = advertising.AdvName;
                    advertising.AdvName = txtAdvTitle.Text.Trim();
                    advertising.AdvName_en = txtAdvTitle_en.Text.Trim();
                    advertising.AdvWidth = int.Parse(txtWidth.Text);
                    advertising.AdvHeight = int.Parse(txtHeight.Text);
                    advertising.Position = ddlPosition.SelectedValue.ToLower().Trim();
                    if (rdbIsImage.Checked)
                    {
                        if (siuUploadAdvertising.HasNewImage == true)
                        {
                            Globals.DelelteFile(Server.MapPath(ConfigPaths.Path_Advertisings_Folder_MapPath + advertising.AdvURL));
                            string fileNameImage = Globals.GetFileName(siuUploadAdvertising.SourceImageClientFileName);
                            siuUploadAdvertising.SaveProcessedImageToFileSystem(ConfigPaths.Path_Advertisings_Folder + fileNameImage);

                            advertising.AdvURL = fileNameImage;
                        }

                        advertising.AdvCode = "";

                        advertising.IsFlash = false;
                        advertising.IsCode = false;
                    }
                    else if (rdbIsGif.Checked)
                    {
                        if (FileUpload2.HasFile)
                        {
                            Globals.DelelteFile(Server.MapPath(ConfigPaths.Path_Advertisings_Folder_MapPath + advertising.AdvURL));
                            string fileNameImage = Globals.GetFileName(FileUpload2.FileName);
                            FileUpload2.SaveAs(Server.MapPath(ConfigPaths.Path_Advertisings_Folder_MapPath + fileNameImage));

                            advertising.AdvURL = fileNameImage;
                        }

                        advertising.AdvCode = "";

                        advertising.IsFlash = false;
                        advertising.IsCode = false;
                    }
                    else if (rdbIsFlash.Checked)
                    {
                        if (FileUpload1.HasFile)
                        {
                            Globals.DelelteFile(Server.MapPath(ConfigPaths.Path_Advertisings_Folder_MapPath + advertising.AdvURL));
                            string fileNameImage = Globals.GetFileName(FileUpload1.FileName);
                            FileUpload1.SaveAs(Server.MapPath(ConfigPaths.Path_Advertisings_Folder_MapPath + fileNameImage));

                            advertising.AdvURL = fileNameImage;
                        }

                        advertising.AdvCode = "";

                        advertising.IsFlash = true;
                        advertising.IsCode = false;
                    }
                    else
                    {
                        advertising.AdvURL = "";
                        advertising.AdvCode = HttpUtility.HtmlEncode(txtMedia.Text.Trim());

                        advertising.IsFlash = false;
                        advertising.IsCode = true;
                    }
                    advertising.AdvLink = txtLink.Text.Trim();
                    advertising.UpdatedBy = Membership.GetUser().UserName;
                    advertising.UpdatedDate = DateTime.Now;
                    if (txtRealeaseDate.Text.Trim() != "")
                    {
                        advertising.ReleaseDate = DateTime.ParseExact(txtRealeaseDate.Text.Trim(), "dd/MM/yyyy hh:mm:ss tt", null);
                    }
                    else
                    {
                        advertising.ReleaseDate = null;
                    }
                    if (txtExpireDate.Text.Trim() != "")
                    {
                        advertising.ExpireDate = DateTime.ParseExact(txtExpireDate.Text.Trim(), "dd/MM/yyyy hh:mm:ss tt", null);
                    }
                    else
                    {
                        advertising.ExpireDate = null;
                    }
                    advertising.DisplayOrder = int.Parse(txtDisplayOrder.Text);
                    advertising.IsActive = chkIsActive.Checked;
                    advertising.ClickCount = 0;
                    string oldCustomerName = advertising.CustomerName;
                    advertising.CustomerName = txtCustomerName.Text.Trim();
                    advertising.Address = txtAddress.Text.Trim();
                    advertising.Phone = txtPhone.Text.Trim();
                    advertising.Fax = txtFax.Text.Trim();
                    advertising.Email = txtEmail.Text.Trim();
                    entity.SaveChanges();
                    CreateDBLog(null, null, TypeAction.Update, "Cập nhật quảng cáo: (" + oldTitle + " - " + txtAdvTitle.Text.Trim() + ") " + "(" + oldCustomerName + " - " + txtCustomerName.Text.Trim() + ")", 
                        "", "", advertising.ReleaseDate != null ? string.Format("{0:dd/MM/yyyy HH:mm:ss}", advertising.ReleaseDate) : "", advertising.ExpireDate != null ? string.Format("{0:dd/MM/yyyy HH:mm:ss}", advertising.ExpireDate) : "",
                        "", "", "", "");
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    lblMessage.Text = "Quảng cáo muốn cập nhật không tồn tại";
                }
            }
        }

        public void CreateDBLog(int? postID, int? postCateID, TypeAction typeAction, string title, string _abstract, string description,
        string releaseDate, string expireDate, string isApproved, string statusID, string metaDescription, string metaKeywords)
        {
            udv_Log log = new udv_Log();
            log.PostID = postID;
            log.PostCateID = postCateID;
            log.TypeAction = (int)typeAction;
            log.Title = title;
            log.Abstract = _abstract;
            log.Description = description;
            log.ReleaseDate = releaseDate;
            log.ExpireDate = expireDate;
            log.IsApproved = isApproved;
            log.StatusID = statusID;
            log.MetaDescription = metaDescription;
            log.MetaKeywords = metaKeywords;
            log.ActionedDate = DateTime.Now;
            log.ActionBy = Membership.GetUser().UserName;
            log.IpAdress = Globals.GetClientIPAddress();

            entity.AddToudv_Log(log);
            entity.SaveChanges();
        }
    }
}